using System;
using System.Web;

namespace CodeStory.Core
{
	public class UserCookie
	{
		private const string cookiename = "CodeStory.Core.UserCookie";
		private HttpCookie cookie;
		private HttpContext context;

		public UserCookie(HttpContext context) {
			this.context = context;
			cookie = context.Request.Cookies[cookiename];
			if (cookie == null) {
				cookie = new HttpCookie(cookiename);
				context.Response.SetCookie(cookie);
			}
		}

		public string SkinName {
			get { return cookie["SkinName"]; }
			set { cookie["SkinName"] = value; }
		}

		#region Save
		public void Save() {
			Save(false);
		}

		public void Save(bool remove) {
			if (remove) {
				cookie.Expires = DateTime.Now.AddDays(-1d);
			}
			context.Response.Cookies.Add(cookie);
		}

		public void Save(double expirs) {
			cookie.Expires = DateTime.Now.AddDays(expirs);
			context.Response.Cookies.Add(cookie);
		}
		#endregion
	}
}